// import * as Mock from 'mockjs'
// const p = Mock.mock({
//   'list|1-20': [
//     {
//       'id|+1': 1,
//       type: '自评'
//     }
//   ]
// })
// console.log(p)
const type = [
  {
    id: 1,
    type: '自评'
  },
  {
    id: 2,
    type: '自评'
  },
  {
    id: 3,
    type: '自评'
  },
  {
    id: 4,
    type: '自评'
  },
  {
    id: 5,
    type: '自评'
  },
  {
    id: 6,
    type: '自评'
  },
  {
    id: 7,
    type: '自评'
  },
  {
    id: 8,
    type: '自评'
  },
  {
    id: 9,
    type: '自评'
  },
  {
    id: 10,
    type: '自评'
  },
  {
    id: 11,
    type: '自评'
  },
  {
    id: 12,
    type: '自评'
  },
  {
    id: 13,
    type: '自评'
  },
  {
    id: 14,
    type: '自评'
  },
  {
    id: 15,
    type: '自评'
  },
  {
    id: 16,
    type: '自评'
  },
  {
    id: 17,
    type: '自评'
  }
]
export default [
  {
    url: '/typeList',
    method: 'get',
    response: (params) => {
      const total = type.length
      const current = params.query.current
      const size = params.query.size
      const right = size * current
      const left = (current - 1) * size
      const data = type.slice(left, right)
      return {
        code: '0000',
        total,
        data
      }
    }
  },
  {
    url: '/addType',
    method: 'post',
    response: (data) => {
      console.log(data.body.type)
      type.unshift({
        id: type.length + 1,
        type: data.body.type
      })
      return {
        code: '0000',
        data: '添加成功'
      }
    }
  },
  {
    url: '/delType',
    method: 'get',
    response: (params) => {
      console.log(params.query.id)
      const id = params.query.id
      const deleteIndex = type.findIndex((item) => {
        return item.id == id
      })
      type.splice(deleteIndex, 1)
      return {
        code: '0000',
        data: '删除成功'
      }
    }
  },
  {
    url: '/editType',
    method: 'post',
    response: (data) => {
      data.body.id
      for (let i = 0; i < type.length; i++) {
        if (type[i].id === data.body.id) {
          type[i] = data.body
        }
      }
      return {
        code: '0000',
        data: '修改成功'
      }
    }
  }
]
